package algorithmTopics.other;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        // 最大通道数量
        int maxLevel = Integer.parseInt(reader.readLine().trim());
        //各阶信道通道数量
        long[] channelCount = parseLoneArray(reader.readLine(),maxLevel + 1);
        // 单用户所需要总容量
        long demand = Long.parseLong(reader.readLine().trim());

        int result = allocateMaxUsers(channelCount,demand,maxLevel);
        System.out.println(result);
    }

    /**
     * 分配最大用户
     *
     * @param channelCount 通道计数
     * @param demand       需求
     * @param maxLevel     最大等级
     * @return int
     */
    private static int allocateMaxUsers(long[] channelCount, long demand, int maxLevel) {
        int served = 0;
        // 一直尝试直到无法再分配
        while (true) {
            //剩余
            long remaining = demand;
            //从最高位开始计算 用恰好等于的方式进行填充
            for (int i = maxLevel; i >=0 ; i--) {
                long cap = 1L << i;
                long use = Math.min(channelCount[i], remaining / cap );
                channelCount[i] -= use;
                remaining -= use*cap;
            }
            // 如果正好凑齐，则计数进入下一轮
            if (remaining == 0) {
                served++;
                continue;
            }
            // 否则在所有还剩余的信道中找到一个最小的容量 >= remaining
            int pick = -1;
            for (int i = 0; i < maxLevel + 1; i++) {
                if (channelCount[i] > 0 && (1L << i) >= remaining) {
                    pick = i;
                    break;
                }
            }
            if (pick < 0) {
                break;
            }
            //用掉这个信道
            channelCount[pick]--;
            served++;
        }


        return served;
    }

    // 字符串转化为 期待的长度的long数组
    private static long[] parseLoneArray(String readLine, int size) {
        StringTokenizer st = new StringTokenizer(readLine);
        long[] arr = new long[size];
        for (int i = 0; i < size; i++) {
            arr[i] = Long.parseLong(st.nextToken());
        }
        return arr;
    }
}
